<?
include_once('conn.php');
include_once('include/func.php');
include("user_check.php") ;

///

if(isset($_GET[cancel])){
	back_to_stock($_GET[cancel],$checkmember[0][2]);
	//$db->update("UPDATE `".tablepre."order` SET `situation`='1' WHERE (`oid`='".$_GET[cancel]."') ");
	header("Location: $nowpage?ok");
	exit;
	}

if(isset($_GET[payment])){
			$order = $db->select("SELECT * FROM `".tablepre."order` where oid = $_GET[oid]");
	$order_item = $db->select("SELECT amount,price FROM `".tablepre."order_item` where oid = $_GET[oid]");
	for($i=0;$i<count($order_item);$i++){
		$order_item_count .= $order_item[$i][0].',';
		$order_price_count .= $order_item[$i][1].',';
		}
		////
	if(array_sum(explode(',',$order_price_count))>mamber($con1=$checkmember[0][2],$con2=7)){
		exit('<script>alert("'.ORDER_DEPOSIT_INSUFFICIENT.'"); location="user_order.php";</script>');
		}
	$db->UPDATE("UPDATE `".tablepre."order` SET `paid`='1' WHERE (`oid`='$_GET[oid]')");
	$db->UPDATE("UPDATE `".tablepre."user` SET advance = concat(advance - ".array_sum(explode(',',$order_price_count)).") , score = concat(score + '".$order[0][17]."') , salesvolume = concat(salesvolume + '".$order[0][18]."')  WHERE (`uid`='".$checkmember[0][2]."')");
	exit('<script>alert("'.PAY_SUCCESSFUL_PAYMENT.'"); location="user_order.php";</script>');
		// echo PAY_SUCCESSFUL_PAYMENT;
		 exit;}
		 
		 if($_POST){
			 echo $o_r=htmlspecialchars($_POST[o_r], ENT_QUOTES);
			// print_r($_POST);
	$db->update("UPDATE `".tablepre."order` SET `situation`='3',`refund`='".$o_r."' WHERE (`oid`='".$_POST[oid]."') ");
	header("Location: $nowpage?ok");
	exit;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo SITE_HEADER; ?></title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
<link href="css/admin.css" rel="stylesheet" type="text/css" />
	<!-- jquery packed -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/dtree.js"></script>
    <script type="text/javascript" src="js/ajaxcart.js"></script>
	<!-- tableRowCheckboxToggle -->
    <script type="text/javascript"> 
    function fade(b) 
{ 
    $('<div id="add" class="quick-alert" style="position:absolute;"><? echo SITE_ADSTATUSOK;?></div>').insertAfter($("#example")).animate({opacity: 1.0}, 2000).fadeOut("slow",function(){ 
   $(this).remove(); 
}); 
} 
</script> 
<script>
function close_facebox(){
	alert('<? echo CART_ADDED; ?>');
 $('#facebox').fadeOut(function() {
      $('#facebox .content').removeClass().addClass('content')
    })
	}
</script>

<link href="js/facefiles/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<script src="js/facefiles/facebox.js" type="text/javascript"></script>
<script src="js/jc_table.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.PrintArea.js"></script>
<script type="text/javascript" src="js/jquery_ajax_order.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox() 
	$("div#print_button").click(function(){
    $("div#myPrintArea").printArea();
	});
	//打印
    })
	////////
</script>
<script type="text/javascript" src="js/jquery.jCountr.1.2.js"></script>
<style>
.j_td{border:#999 solid 1px;}
.pay{ width:500px;}
</style>
</head>
<body <? echo isset($_GET[ok])?'onload="fade();"':''; ?>>
<div id="wrap">
<div id="main" class="clearfix">
<div id="side">
  </div>
  <div id="head"><? include_once('user_head.php');?></div><table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="13%" valign="top"><div id="left"> <?
  include_once('user_menu.php');
  ?></div></td>
    <td width="87%" align="left" valign="top"><div id="example"> </div><div id="myPrintArea"><img src="images/ttfjpg.php?t=<? echo ORDER_MY_ORDER;?>&bg=titlebg2.jpg&z=18&x=5&y=22&r=0&b=0&g=0"  /><br />

      
      
      <table border="0" cellspacing="1" cellpadding="0" class="jc_table">

  <tr class="header">
    <td><? echo ORDER_SN;?></td>
    <td><? echo ORDER_EXPRESS_SN;?></td>
    <td><? echo PAY_PAYMENT_METHOD;?></td>
    <td><? echo ORDER_TOTAL;?></td>
    <td><? echo PAY_ITEM_QUANTITY;?></td>
    <td><? echo ORDER_DATE;?></td>
    <td><? echo ORDER_STATUS;?></td>
    <td><? echo ORDER_OPERATION;?></td>
    <td><? echo ORDER_PRINT;?></td>
    <td><? echo ORDER_REORDER;?></td>
    <td><? echo ORDER_COUNT_DOWN;?></td>
    
  </tr>
      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where uid = '".$checkmember[0][2]."' and paid = 0 and situation = 0 and `delete` = '0' order by datetime desc");
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><? echo $order_list[$i][3];?></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td><a href="include/pay.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.pay]"><? echo PAY_NOW;?></a></td>
      <td><a href="include/user_check_order.php?action=1&oid=<? echo $order_list[$i][0];?>" rel="facebox"><? echo ORDER_CHECK;?></a> | <a href="?cancel=<? echo $order_list[$i][0];?>" onclick="return confirm('<? echo CART_ARE_YOU_SURE; ?>')" ><? echo ORDER_CANCEL;?></a></td>
       <td align="center"><a href="include/user_print.php?action=order&oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
       <td align="center"><a href="javascript:void(0);" onClick="if(confirm('<? echo ORDER_REORDER_WARNING;?>')) reorder('<? echo $order_list[$i][0];?>')"><img src="images/icon_8.gif" /></a><div id="loading<? echo $order_list[$i][0];?>" style=" display:none;"></div></td>
       <td align="center"><?  
	   $extime = (strtotime($order_list[$i][11])+(parameters(23)*3600));
	   $ex = strtotime(date('Y-m-d H:i:s',$extime))-strtotime(date('Y-m-d H:i:s'));
	   $ex = round($ex/3600,4);
	   ?>
       <script type="text/javascript"> 
$(document).ready(function(){
	$("#countdown<? echo $i;?>").counter({hour:"<? echo $ex;?>"});
});
</script>
<div id="countdown<? echo $i;?>"></div></td>
      </tr>
<? } ?>
      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where uid = '".$checkmember[0][2]."' and paid = 1 and situation = 0 and `delete` = '0' order by datetime desc");
	  	  if(count($order_list)>0){
		  ?>
		      <tr>
      <td colspan="11" class="middle"><? echo PAY_PAID;?></td>
      </tr>
		  <?
		  }
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><? echo $order_list[$i][3];?></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td><? echo PAY_PAID;?></td>
      <td><a href="include/user_check_order.php?action=1&oid=<? echo $order_list[$i][0];?>" rel="facebox"><? echo ORDER_CHECK;?></a></td>
      <td align="center"><a href="include/user_print.php?action=order&oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
       <td align="center"><a href="javascript:void(0);" onClick="if(confirm('<? echo ORDER_REORDER_WARNING;?>')) reorder('<? echo $order_list[$i][0];?>')"><img src="images/icon_8.gif" /></a><div id="loading<? echo $order_list[$i][0];?>" style=" display:none;"></div></td>
       <td></td>
      </tr>

<? } ?>

      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where uid = '".$checkmember[0][2]."' and paid = 1 and situation = 2 and `delete` = '0' order by express_time desc");
	  	  if(count($order_list)>0){
		  ?>
		      <tr>
      <td colspan="11" class="middle"><? echo ORDER_SENT;?></td>
      </tr>
		  <?
		  }
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><? echo $order_list[$i][3];?></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td><? echo PAY_PAID;?></td>
      <td><a href="include/user_check_order.php?action=1&oid=<? echo $order_list[$i][0];?>" rel="facebox"><? echo ORDER_CHECK;?></a> | <a href="include/refund.php?oid=<? echo $order_list[$i][0];?>" rel="facebox" ><? echo ORDER_REFUND;?></a></td>
      <td align="center"><a href="include/user_print.php?action=order&oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      <td align="center"><a href="javascript:void(0);" onClick="if(confirm('<? echo ORDER_REORDER_WARNING;?>')) reorder('<? echo $order_list[$i][0];?>')"><img src="images/icon_8.gif" /></a><div id="loading<? echo $order_list[$i][0];?>" style=" display:none;"></div></td>
      <td></td>
      </tr>

<? } ?>

      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where uid = '".$checkmember[0][2]."' and situation = 1 and `delete` = '0' order by express_time desc");
	  	  if(count($order_list)>0){
		  ?>
		      <tr>
      <td colspan="11" class="middle"><? echo ORDER_TIMEOUT;?></td>
      </tr>
		  <?
		  }
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><? echo $order_list[$i][3];?></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td><? echo ORDER_TIMEOUT2;?></td>
      <td><a href="include/user_check_order.php?action=1&oid=<? echo $order_list[$i][0];?>" rel="facebox"><? echo ORDER_CHECK;?></a></td>
      <td align="center"><a href="include/user_print.php?action=order&oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      <td align="center"><a href="javascript:void(0);" onClick="if(confirm('<? echo ORDER_REORDER_WARNING;?>')) reorder('<? echo $order_list[$i][0];?>')"><img src="images/icon_8.gif" /></a><div id="loading<? echo $order_list[$i][0];?>" style=" display:none;"></div></td>
      <td></td>
      </tr>

<? } ?>
  </table></div>
<div id="print_button" style="width:32px; height:32px;"><a href="javascript:void(0);"><img src="images/print.png" /></a></div></td>
  </tr>
</table>
 
  
  </div>
  </div>

<div id="footer">
<?
include_once('fooder.php');
?>
</div>
</BODY>
</HTML>